package com.sxj.corejava.code07_面向对象.多态;


import java.util.Scanner;

/**
 * @author 石小俊
 * @date 2025年07月21日 11:43
 * 去宠物店领养宠物, 可以选择三种宠物 1.狗狗 2.猫咪 3.猪猪
 * 宠物Pet存在两个属性:name(姓名)、gender(性别)
 * 狗狗Dog存在一个自己的属性:age(年龄)
 * 猫咪Cat存在一个自己的属性:type(品种)
 * 猪猪Pig存在一个自己的属性:hobby(爱好)
 * 每一个宠物都有一个show方法, 用于打印对应的宠物信息
 * 通过用户输入不同选项选择对应宠物,打印出对应宠物的信息
 */
public class Test02_练习 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("************************欢迎来到紫金宠物店************************");
        System.out.print("请选择领养的宠物类型(1.狗狗 2.猫咪 3.猪猪):");
        int choice = sc.nextInt();
        Pet pet = null;
        String name = null;
        String gender = null;
        switch (choice) {
            case 1:
                System.out.print("请为您的宠物狗取一个名字:");
                name = sc.next();
                System.out.print("请输入您的宠物性别:");
                gender = sc.next();
                System.out.println("请输入您的宠物年龄:");
                int age = sc.nextInt();
                pet = new Dog(name, gender, age);
                break;
            case 2:
                System.out.print("请为您的宠物狗取一个名字:");
                name = sc.next();
                System.out.print("请输入您的宠物性别:");
                gender = sc.next();
                System.out.print("请输入您选择的宠物品种:");
                String type = sc.next();
                pet = new Cat(name, gender, type);
                break;
            case 3:
                System.out.print("请为您的宠物狗取一个名字:");
                name = sc.next();
                System.out.print("请输入您的宠物性别:");
                gender = sc.next();
                System.out.print("请输入宠物的爱好:");
                String hobby = sc.next();
                pet = new Pig(name, gender, hobby);
                break;
            default:
                System.out.println("错误:您输入的选项有误!");
                return;
        }
        pet.show();
    }
}

class Pet {
    private String name;
    private String gender;

    public Pet(String name, String gender) {
        this.name = name;
        this.gender = gender;
    }

    public void show() {
        System.out.println("这是一只宠物");
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getGender() {
        return gender;
    }

    public void setGender(String gender) {
        this.gender = gender;
    }
}

class Dog extends Pet {
    private int age;

    public Dog(String name, String gender, int age) {
        super(name, gender);
        this.age = age;
    }

    public void show() {
        System.out.println("这是一只宠物狗,名字:" + getName() + ",性别:" + getGender() + ",年龄:" + age);
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }
}

class Cat extends Pet {
    private String type;

    public Cat(String name, String gender, String type) {
        super(name, gender);
        this.type = type;
    }

    public void show() {
        System.out.println("这是一只宠物猫,名字:" + getName() + ",性别:" + getGender() + ",品种:" + type);
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }
}

class Pig extends Pet {
    private String hobby;

    public Pig(String name, String gender, String hobby) {
        super(name, gender);
        this.hobby = hobby;
    }

    public void show() {
        System.out.println("这是一只宠物猪,名字:" + getName() + ",性别:" + getGender() + ",爱好:" + hobby);
    }

    public String getHobby() {
        return hobby;
    }

    public void setHobby(String hobby) {
        this.hobby = hobby;
    }
}
